#include "WindowController.h"
#include "ViewController.h"
#include "Window.h"
#include "DebugLog.h"
#include "View.h"

WindowController::WindowController( Window* window ) : _window( window ), _viewController( 0 )
{
	//TRACEFUNC
}

WindowController::~WindowController( )
{
	//TRACEFUNC
	delete viewController();
	delete window();
}

void WindowController::setWindow( Window* newWindow )
{
	if ( window() != newWindow )
	{
		delete _window;
		_window = newWindow;
	}
}

Window*	WindowController::window( )
{
	if ( !_window )
	{
		_window = new Window();
	}
	return _window;
}

void WindowController::updateWindow( )
{
	window()->update();
}

ViewController* WindowController::viewController( ) 
{
	if ( !_viewController )
	{
		_viewController = new ViewController( );
		//window()->contentView( _viewController->view() );
	}
	return _viewController;
}

void WindowController::setViewController( ViewController* viewContr )
{
	//TRACEFUNC
	
	if ( viewController() != viewContr )
	{
		//delete _viewController;

		_viewController = viewContr;

		if ( _viewController )
		{
			window()->contentView()->deleteAllSubViews();
			window()->contentView()->addSubView( _viewController->view() );
		}
	}
}